import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { SimpleAnimate } from '../../../share/animation/my.simple.animation';

import { Grid } from '../../../share/model/grid.model';

import { HttpService } from '../../../share/http/http.service';
import { NoticeService } from '../../../share/service/notice.service';

import { ConfirmDialogService } from '../../../share/service/confirm.service';

@Component({
  selector: 'hk-role-list',
  templateUrl: './role.list.component.html',
  styleUrls: ['./role.list.component.css'],
  animations: [SimpleAnimate]
})
export class RoleListComponent implements OnInit {

  private columns = [
    { title: '', field: 'id', hidden: true },
    { title: '角色名', field: 'roleName' },
    { title: '描述', field: 'description' },
    {
      title: '状态', field: 'roleStatus', formatter: function (row: any): any {
        if (row.roleStatus === 0) {
          return '<span class="label label-success">启用</span>';
        } else {
          return '<span class="label label-danger">禁用</span>';
        }
      }
    },
    { title: '创建时间', field: 'createTime' },
  ];

  searchBody = {
    roleName: ''
  };

  // 表格
  grid: Grid = new Grid(this.httpService, this.noticeService, this.confirmDialogService, this.router);

  constructor(
    private httpService: HttpService,
    private noticeService: NoticeService,
    private confirmDialogService: ConfirmDialogService,
    private router: Router) { }


  ngOnInit() {
    this.initGrid();
  }

  search() {
    this.grid.reload();
  }

  clearSearch() {
    this.searchBody.roleName = '';
    this.search();
  }

  add() {
    this.grid.add('/main/role/edit');
  }

  edit() {
    this.grid.edit('/main/role/edit');
  }

  remove() {
    this.grid.remove('role/delete/');
  }

  private initGrid() {
    let options = {
      url: 'role/list',
      columns: this.columns,
      searchBody: this.searchBody,
    };
    this.grid.initOptions(options);
    this.grid.load();
  }

}
